<!--
 * @FilePath     : /study_code/html/iframe-parent.html
 * @Description  : iframe 同域通讯 （父页面）
 * @Date         : 2025-04-25 14:07:58
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-25 14:10:16
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <h2>父页面</h2>
    <textarea id="message">父父父txt</textarea>
    <br />
    <button id="test">获取内容</button>

    <p>下面是 iframe 嵌入的 子页面</p>
    <iframe id="iframe" src="/html/iframe-child.html" width="500" height="300"></iframe>

    <script>
      document.getElementById('test').onclick = function () {
        console.log(
          1,
          document.getElementById('iframe').contentWindow.document.getElementById('message').value // 1 '子子子txt'
        )
      }
    </script>
  </body>
</html>
